package org.misalen.web.database.repository.mysql;

import java.util.Date;

import org.misalen.web.database.dao.mysql.impl.BaseMySqlDaoImpl;
import org.misalen.web.database.model.mysql.pro.ProSmsCode;
import org.springframework.stereotype.Repository;

@Repository
public class ProSmsCodeRepository extends BaseMySqlDaoImpl<ProSmsCode> {

	public long countMobileAndTime(String mobile, Long smsfrequency, String smsSendType) {
		String sql = "select count(*) from ProSmsCode where mobile=?0 and type=?1 and addTime>?2";
		return count(sql, new Object[] { mobile, smsSendType, new Date(System.currentTimeMillis() - smsfrequency) });
	}

	public long countMobileTimeAndCode(String mobile, String code, Long smsValidity, String smsSendType) {
		String sql = "select count(*) from ProSmsCode where mobile=?0 and type=?1 and addTime>?2 and code=?3";
		return count(sql,
				new Object[] { mobile, smsSendType, new Date(System.currentTimeMillis() - smsValidity), code });
	}
}